from django.contrib.auth import get_user_model
from django.db import models


# Create your models here.


class NewsCategory(models.Model):
    name = models.CharField(max_length=100, unique=True)

    class Meta:
        db_table = 'news_category'
        verbose_name = '新闻分类'
        verbose_name_plural = verbose_name


class News(models.Model):
    title = models.CharField(max_length=200)
    desc = models.CharField(max_length=200)
    thumbnail = models.URLField()
    content = models.TextField()
    pub_time = models.DateTimeField(auto_now_add=True)

    category = models.ForeignKey(NewsCategory, on_delete=models.SET_NULL, null=True)
    author = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True)

    class Meta:
        ordering = ['-pub_time']
        db_table = 'news'
        verbose_name = '新闻'
        verbose_name_plural = verbose_name


class NewsComment(models.Model):
    content = models.TextField()
    pub_time = models.DateTimeField(auto_now_add=True)

    news = models.ForeignKey(News, on_delete=models.CASCADE)
    author = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)

    class Meta:
        ordering = ['-pub_time']
        db_table = 'news-comments'
        verbose_name = '新闻评论'
        verbose_name_plural = verbose_name


#
class Focus(models.Model):
    thumbnail = models.URLField()
    link_to = models.URLField()
    desc = models.CharField(max_length=100)
    PRIORITY = (
        (1, '第一级'),
        (2, '第二级'),
        (3, '第三级'),
        (4, '第四级'),
        (5, '第五级'),
        (6, '第六级'),
    )
    priority = models.IntegerField(choices=PRIORITY)

    class Meta:
        ordering = ['priority']
        db_table = 'news-focus'
        verbose_name = '轮播图'
        verbose_name_plural = verbose_name
